# ROT13 example
# Michael S. Sanders
# license: GPL3

BEGIN {

tmp1 = rot13("Neato Buritto")
tmp2 = rot13(tmp1)

print tmp1
print tmp2

}

# ----------------------------------------------------------------------

function rot13(str,    from, to, x, y, z, letter, char, buf) {

# more info about rot13 at: http://en.wikipedia.org/wiki/ROT13
# a modification of the example found at:
# http://www.miranda.org/~jkominek/rot13/awk/

from = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm0987654321"
to   = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"

x    = length(from)
y    = length(str)

    for (z = 1; z <= x; z++) {
         letter[substr(from, z, 1)] = substr(to, z, 1)
    }

    for (z = 1; z <= y; z++) {
        char = substr(str, z, 1)
        buf  = (char in letter) ? buf letter[char] : buf char
    }

return buf

}
